import { CHAT_STORE} from '@/constants';
import {atom, selector} from 'recoil';
import {Contact, MessageDataMap} from "@/pages/Message/typing";

export enum MessageType  {
  CHAT  = "chat",
  USER_DATA  = "user_data",
  USER_LIST  = "user_list",
  USER_ID = "user_id"
}

export const userListStore = atom<Contact[]>({
  key: CHAT_STORE,
  default: [] as Contact[],
});

export const userDataStore = atom<MessageDataMap>({
  key: "userDataStore",
  default: {} as MessageDataMap,
});

export const currentUserStore = atom<Contact>({
  key: "currentUserStore",
  default: {id : 0},
});

export const currentUserDataStore = selector({
  key: 'currentUserDataStore',
  get: ({ get }) => {
    const curUser = get(currentUserStore)
    const userData = get(userDataStore)
    return userData[curUser.id]
  },
})
